package benny.ApkposStore.Adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import benny.ApkposStore.R;
import benny.ApkposStore.utils.ApkUntils;

public class RoomAdapter extends BaseAdapter {

	private Context context;
	private List<HashMap<String, Object>> list;
	private LayoutInflater mInflater;
//	private TextPaint tp = null;

	public RoomAdapter(Context context, List<HashMap<String, Object>> list2) {
		this.context = context;
		this.list = list2;
		mInflater = LayoutInflater.from(this.context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null)
			return list.size();
		else
			return 0;
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if (list != null)
			return list.get(position);
		else
			return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressWarnings("unused")
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (holder == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.roompanel, null);
			holder.roomtitle = (TextView) convertView
					.findViewById(R.id.room_title);
			holder.room_cnt = (TextView) convertView
					.findViewById(R.id.room_cnt);
			holder.time = (TextView) convertView.findViewById(R.id.room_time);
			holder.roompayment = (TextView) convertView
					.findViewById(R.id.room_payment);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		/*
		 * //绑定点击事件 holder.roomtitle.setOnClickListener((OnClickListener)
		 * list.get(position).get("listen")); //通过标志位控制按钮的Enable
		 * if(Boolean.parseBoolean(list.get(position).get("bl").toString()))
		 * holder.roomtitle.setEnabled(true); else
		 * holder.roomtitle.setEnabled(false);
		 */
		holder.roomtitle
				.setText(list.get(position).get("room_name").toString());
		int cnt=Integer.parseInt(list.get(position).get("room_cnt").toString());
		holder.cnt=cnt;   
		if (cnt>1) {
			holder.room_cnt
			.setText(list.get(position).get("room_cnt").toString());	
		}
		else {
			holder.room_cnt.setText("");
		}
		
		if (list.get(position).get("orderid")!=null) {
			holder.orderid=list.get(position).get("orderid").toString();
		}
	
		
		holder.roomtitle.setHint(list.get(position).get("room_id").toString());
		 float payment = Float.parseFloat(list.get(position).get("room_payment").toString());
		
		if (payment==0) {
			holder.roompayment.setText("");
		} else {
			holder.roompayment.setText(list.get(position).get("room_payment")
					.toString());

		}
		if (list.get(position).get("room_time").toString().equals("0")) {
			holder.time.setText("");
		} else {
			holder.time.setText(list.get(position).get("room_time").toString());
		}

		holder.roomtitle.setBackgroundResource(Integer.parseInt(list
				.get(position).get("icon").toString()));
		holder.price_type=(Integer) list.get(position).get("price_type");
       // System.out.println("holder.price_type"+holder.price_type);

		// tp = holder.roomtitle.getPaint();
		// tp.setFakeBoldText(true);

		return convertView;
	}

	public final class ViewHolder {
		public TextView roomtitle;
		public TextView room_cnt;
		public TextView time;
		public TextView roompayment;
		public int price_type;
		public int cnt;
		public String orderid;
	}
}